# 首先添加Python包搜索路径
import sys
import os
# 添加当前目录到Python路径
sys.path.append(os.path.dirname(os.path.abspath(__file__)))

from flask import Flask, send_from_directory
from flask_cors import CORS

# 正确设置静态文件夹路径
app = Flask(__name__, static_folder='docs/static/assets')
CORS(app)

# 首页路由
@app.route('/')
def index():
    # 返回dashboard.html文件
    return send_from_directory('docs/static/assets/html', 'dashboard.html')

# 数据大屏路由
@app.route('/dashboard')
@app.route('/dashboard.html')
def dashboard():
    return send_from_directory('docs/static/assets/html', 'dashboard.html')

# 评论详情路由
@app.route('/comments_detail')
@app.route('/comments_detail.html')
def comments_detail():
    return send_from_directory('docs/static/assets/html', 'comments_detail.html')

# 笔记详情路由
@app.route('/notes_detail')
@app.route('/notes_detail.html')
def notes_detail():
    return send_from_directory('docs/static/assets/html', 'notes_detail.html')

# NLP分析路由
@app.route('/nlp_detail')
@app.route('/nlp_detail.html')
def nlp_detail():
    return send_from_directory('docs/static/assets/html', 'nlp_detail.html')

# 通用文件服务路由
@app.route('/<path:path>')
def serve_file(path):
    # 尝试从docs/static/assets目录提供文件（匹配CSS、JS等资源）
        return send_from_directory('docs/static/assets', path)
#添加visualization目录路由
@app.route('/visualization/<path:path>')
def serve_visualization_file(path):
    return send_from_directory('docs/static/visualization', path)

# 添加data目录路由
@app.route('/data/<path:path>')
def serve_data_file(path):
    return send_from_directory('data', path)

if __name__ == '__main__':
    app.run(host='0.0.0.0', port=8000, debug=True)